home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 29.3 KB | 937 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSView.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWVIEW_H
- #include "FWSView.h"
- #endif
-
- #ifndef FWAROPER_H
- #include "FWArOper.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESACC_H
- #include "FWResAcc.h"
- #endif
-
- #ifndef FWRESSIN_H
- #include "FWResSin.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #if defined(__MWERKS__) && GENERATING68K
- // A hack to work around a bug
- #pragma import list somGetGlobalEnvironment
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwview
- #endif
-
-
- //========================================================================================
- // class FW_CSuperViewCollection
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CSuperViewCollection)
-
- //========================================================================================
- // class FW_CSuperViewCollectionIterator
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CSuperViewCollectionIterator)
-
- //========================================================================================
- // CLASS FW_CSuperView
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CSuperView, FW_CView)
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::FW_CSuperView
- //----------------------------------------------------------------------------------------
- FW_CSuperView::FW_CSuperView(Environment* ev, FW_CSuperView* container,
- const FW_CRect& bounds, ODID theID, const FW_CPoint& extent,
- FW_EScrollingDirection scrollDir) :
- FW_CView(ev, container, bounds, theID),
- fSubViews(NULL),
- fIsContentView(FALSE),
- fViewContentToFrameTransform(NULL),
- fScrollingDirection(scrollDir),
- fInternalTransform(NULL)
- {
- // Use the view's size as its default extent
- fExtent = (extent == FW_kZeroPoint) ? fBounds.Size() : extent;
-
- // Unlike FW_CView, by default superviews are not refreshed entirely when resized
- // i.e. FW_CSuperView subclasses must set the flag back to true if their content
- // depends on the size.
- SetResizeForceRedraw(ev, false);
-
- // Change the default binding, because this makes more sense for a content view
- SetBindings(ev, FW_kFitToEnclosure);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::FW_CSuperView
- //----------------------------------------------------------------------------------------
-
- FW_CSuperView::FW_CSuperView(Environment* ev) :
- FW_CView(ev),
- fSubViews(NULL),
- fIsContentView(FALSE),
- fExtent(FW_kZeroPoint),
- fViewContentToFrameTransform(NULL),
- fScrollingDirection(FW_kNoScrolling),
- fInternalTransform(NULL)
- {
- // this ctor should be used by CFrame only, the only CSuperView with a NULL fSuperView
- SetResizeForceRedraw(ev, false);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::~FW_CSuperView
- //----------------------------------------------------------------------------------------
-
- FW_CSuperView::~FW_CSuperView()
- {
- Environment *ev = somGetGlobalEnvironment();
-
- DeleteSubViews(ev);
-
- if (fViewContentToFrameTransform)
- {
- fViewContentToFrameTransform->Release(ev);
- fViewContentToFrameTransform = NULL;
- }
-
- if (fInternalTransform)
- fInternalTransform->Release(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::DeleteSubViews
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::DeleteSubViews(Environment* ev)
- {
- FW_UNUSED(ev);
- if (fSubViews)
- {
- FW_CView* view;
- while (fSubViews != NULL && (view = fSubViews->Last()) != NULL)
- {
- // Delete each subview, which in turn will remove it from its parentView
- // fSubViews is deleted after the last view is removed
- delete view;
- }
-
- // delete fSubViews;
- // fSubViews = NULL;
- FW_ASSERT(fSubViews == NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::IsScrolling
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSuperView::IsScrolling(Environment* ev) const
- {
- return IsScrollingInX(ev) || IsScrollingInY(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivSetContentExtent
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivSetContentExtent(Environment* ev, const FW_CPoint& extent)
- {
- ODPoint odPoint = extent;
-
- FW_CFrame* frame = GetFrame(ev);
- frame->GetODFrame(ev)->ChangeContentExtent(ev, &odPoint);
-
- if (IsScrolling(ev))
- frame->PrivUpdateScrollParameters(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SetExtent
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::SetExtent(Environment* ev, const FW_CPoint& extent)
- {
- if (fExtent != extent)
- {
- FW_CPoint oldExtent = fExtent;
- fExtent = extent;
-
- // Changing the extent triggers the layout manager
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- // Resize each subview and update the screen
- subview->AdjustToNewLayout(ev, oldExtent, extent, true);
- }
-
- // The Content View must also udpate the ODFrame's extent and adjust scroller
- if (fIsContentView)
- PrivSetContentExtent(ev, extent);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SetSize
- //----------------------------------------------------------------------------------------
- // WARNING: this method should not be called directly by instances of FW_CFrame.
- // FW_CFrame calls it internally in FrameShapeChanged, you cannot control the
- // size of your frame with SetSize, use FW_MProxy::ChangeFrameShapes
-
- void FW_CSuperView::SetSize(Environment* ev, const FW_CPoint& size, FW_Boolean refresh)
- {
- // Call base class first
- FW_CView::SetSize(ev, size, refresh);
-
- if (IsScrolling(ev) == false)
- {
- // Set the extent to match the new size when the superview is not scrolling
- // SetExtent will in turn adjust the layout of the superview's subviews
- SetExtent(ev, size);
- }
- else
- {
- // There are 3 types of scrolling views:
- // - scrolling only in X -> the extent height is adjusted
- // - scrolling only in Y -> the extent width is adjusted
- // - scrolling in X and Y -> the extent is not changed
- FW_CPoint extent = fExtent;
-
- if (IsScrollingInX(ev) == true && IsScrollingInY(ev) == false)
- extent.y = size.y;
-
- if (IsScrollingInY(ev) == true && IsScrollingInX(ev) == false)
- extent.x = size.x;
-
- SetExtent(ev, extent);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::MakeContentView
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::MakeContentView(Environment* ev)
- {
- FW_CFrame* frame = GetFrame(ev);
-
- // Declare ContentView to the CFrame
- frame->SetContentView(ev, this);
- fIsContentView = TRUE;
-
- // Update the ODFrame's extent and the scrollbars
- PrivSetContentExtent(ev, fExtent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::AddSubView
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::AddSubView(Environment* ev, FW_CView *subview)
- {
- if (fSubViews == NULL)
- {
- fSubViews = FW_NEW(FW_CViewCollection, ());
- }
- else if (fSubViews->Contains(this) == true)
- {
- FW_DEBUG_MESSAGE("subview already added");
- return;
- }
-
- // AddSubView can be used to replace an existing parent view
- FW_CSuperView* oldParent = subview->fSuperView;
- if (oldParent != this && oldParent != NULL)
- {
- // This will in turn call PrivInvalidateCachedTransforms
- oldParent->RemoveSubView(ev, subview);
-
- subview->fSuperView = this;
- }
-
- fSubViews->AddLast(subview);
-
- // Virtual method for subclasses
- SubViewAdded(ev, subview);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SubViewAdded
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::SubViewAdded(Environment* ev, FW_CView* subview)
- {
- FW_UNUSED(ev);
- FW_UNUSED(subview);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::RemoveSubView
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::RemoveSubView(Environment* ev, FW_CView* subview)
- {
- FW_ASSERT(fSubViews != NULL);
- FW_ASSERT(fSubViews->Contains(subview));
-
- fSubViews->Remove(subview);
-
- // Reset subview geometry
- subview->PrivInvalidateCachedTransforms(ev);
-
- // Virtual method for subclasses
- SubViewRemoved(ev, subview);
-
- // Update fSuperView field in case it's added to another superview
- subview->fSuperView = NULL;
-
- if (fSubViews->Last() == NULL)
- {
- delete fSubViews;
- fSubViews = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SubViewRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::SubViewRemoved(Environment* ev, FW_CView* subview)
- {
- FW_UNUSED(ev);
- FW_UNUSED(subview);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::AdjustCursor
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- FW_Boolean FW_CSuperView::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
- {
- // If I am the content view let the frame do the job first
- if (fIsContentView) return GetFrame(ev)->AdjustCursor(ev, odFacet, theMousePoint);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::CountSubViews
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CSuperView::CountSubViews(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fSubViews == NULL ? 0 : fSubViews->Count();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::HasSubViews
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSuperView::HasSubViews(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fSubViews != NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::FindViewById
- //----------------------------------------------------------------------------------------
- FW_CView* FW_CSuperView::FindViewById(Environment* ev, ODID id)
- {
- FW_CView* theView = NULL;
-
- if (GetViewId(ev) == id) {
- theView = this;
- }
- else {
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- theView = subview->FindViewById(ev, id);
- if (theView) break;
- }
- }
- return theView;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::CreateSubViews(Environment *ev)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::CreateSubViewsFromResource
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::CreateSubViewsFromResource(Environment* ev, FW_ResourceId id)
- {
- FW_TRY
- {
- FW_CSharedLibraryResourceFile resFile(ev, GetFrame(ev)->GetPart(ev)->GetPartInstance(ev));
- FW_PResource viewResource(ev, resFile, id, FW_kViewLayoutType);
- FW_PResourceSink sink(ev, viewResource);
- FW_CReadableStream stream(sink);
- CreateSubViewsFromStream(ev, stream);
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, except)
- {
- // We use this try-catch block purely to warn about a common mistake.
- // If one forgets to add the resource containing their views to their project,
- // or passes in the wrong view id, the above code will throw an exception
- // that probably won't get caught until the SOM entry point from OpenDoc.
- // OpenDoc will display an error dialog that isn't particularly helpful
- // in diagnosing the problem.
- FW_DEBUG_MESSAGE("Failed to load view resource.");
- FW_PlatformError error = except.GetPlatformError();
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::CreateSubViewsFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::CreateSubViewsFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CPoint realExtent = fExtent;
-
- // Load the extent used in resources to define the layout of subviews
- stream >> fExtent;
-
- // Create the subviews
- PrivCreateSubViewsFromStream(ev, stream);
-
- // Give subclass a chance to complete subviews creation
- PrivPostCreateViewFromStream(ev);
-
- // Reset the superview's extent like it was and adjust the subviews layout in the process
- SetExtent(ev, realExtent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivCreateSubViewsFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivCreateSubViewsFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_PREREGISTER_RUNTIME_OBJECT(stream,
- this,
- FW_kPreregisteredRootViewObject);
-
- PrivReadSubviewsFromStream(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivPostCreateViewFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivPostCreateViewFromStream(Environment* ev)
- {
- // Handle this view first
- PostCreateViewFromStream(ev);
-
- // Propagate to subviews
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- if (subview->HasSubViews(ev))
- ((FW_CSuperView *)subview)->PrivPostCreateViewFromStream(ev);
- else
- subview->PostCreateViewFromStream(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::GetViewContaining
- //----------------------------------------------------------------------------------------
- // Find the visible & enabled view containing a point (in frame coordinates)
-
- FW_CView* FW_CSuperView::GetViewContaining(Environment* ev,
- ODFacet* odFacet,
- const FW_CPoint& theMousePoint)
- {
- FW_CView* viewUnder = NULL;
-
- if (fVisible && IsEnabled(ev) && IsMouseWithin(ev, odFacet, theMousePoint))
- {
- // iterate on sibling views from top to bottom
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.Last(); ite.IsNotComplete() && !viewUnder;
- subview = ite.Previous())
- {
- viewUnder = subview->GetViewContaining(ev, odFacet, theMousePoint);
- }
- if (viewUnder == NULL)
- viewUnder = this;
- }
-
- return viewUnder;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
- {
- FW_UNUSED(oldSize);
- if (IsContentView(ev) && IsScrolling(ev))
- GetFrame(ev)->PrivUpdateScrollParameters(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SetLocation
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::SetLocation(Environment* ev, const FW_CPoint& location, FW_Boolean refresh)
- {
- FW_CPoint newLocation;
- if (IsContentView(ev))
- {
- newLocation = location;
- FW_CSuperView* parent = GetSuperView(ev);
- if (parent)
- parent->ViewContentToFrame(ev, newLocation);
- }
-
- FW_CView::SetLocation(ev, location, refresh);
-
- if (IsContentView(ev))
- GetFrame(ev)->PrivContentViewLocationChanged(ev, newLocation);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::IsInContentView
- //----------------------------------------------------------------------------------------
- // [LSD] keep that?
- FW_Boolean FW_CSuperView::IsInContentView(Environment* ev) const
- {
- if (fIsContentView)
- return TRUE;
- else if (IsFrame(ev))
- return FALSE; // this is the CFrame but its fIsContentView was FALSE
- else
- return fSuperView->IsInContentView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::AcquireViewContentToFrameTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view content coordinates to frame coordinates
-
- ODTransform* FW_CSuperView::AcquireViewContentToFrameTransform(Environment* ev) const
- {
- FW_CSuperView* self = (FW_CSuperView*)this;
-
- if (fViewContentToFrameTransform == NULL)
- {
- self->fViewContentToFrameTransform = FW_CopyAndRelease(ev, PrivAcquireViewInternalTransform(ev));
- FW_CAcquiredODTransform aqViewToFrame = AcquireViewToFrameTransform(ev);
- fViewContentToFrameTransform->PostCompose(ev, aqViewToFrame);
- }
-
- self->fViewContentToFrameTransform->Acquire(ev);
-
- return fViewContentToFrameTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::GetBoundsInContent
- //----------------------------------------------------------------------------------------
- // returns the bounds in content coordinates
-
- FW_CRect FW_CSuperView::GetBoundsInContent(Environment *ev) const
- {
- FW_CRect bounds = GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- FW_CAcquiredODTransform aqInternal = PrivAcquireViewInternalTransform(ev);
- bounds.InverseTransform(ev, aqInternal);
-
- return bounds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::HandleActivateEvent
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
- {
- // Activate this view and then its subviews
- FW_CView::HandleActivateEvent(ev, theActivateEvent);
-
- FW_CViewIterator ite(this);
- for (FW_CView* view = ite.First(); ite.IsNotComplete(); view = ite.Next())
- {
- view->HandleActivateEvent(ev, theActivateEvent);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::HandleMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CSuperView::HandleMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_Boolean inActiveWindow = frame->GetWindow(ev)->IsActive(ev);
-
- FW_Boolean clickedInFrame = fIsContentView || !frame->IsRoot(ev);
- if (frame->PrivActiveWindowOnMouseDown(ev, theMouseEvent.GetFacet(ev), clickedInFrame))
- return TRUE;
-
- if (fIsContentView)
- {
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, FALSE);
- }
-
- if (inActiveWindow)
- {
- if (this->WantsToBeTarget(ev))
- this->BecomeTarget(ev);
-
- FW_MEventHandler::HandleMouseDown(ev, theMouseEvent);
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::HandleDraw
- //----------------------------------------------------------------------------------------
- // invalidShape is in frame coordinate (NULL means redraw everything)
-
- FW_Boolean FW_CSuperView::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- if (FW_CView::HandleDraw(ev, odFacet, invalidShape)) {
- // Draw its subviews
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- subview->HandleDraw(ev, odFacet, invalidShape);
- }
- }
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::Draw
- //----------------------------------------------------------------------------------------
- // invalidShape is in content coordinate of this view
-
- void FW_CSuperView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(invalidShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::GetExtent
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CSuperView::GetExtent(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::SetVisible
- //----------------------------------------------------------------------------------------
- // [LSD] use tri-state later
-
- void FW_CSuperView::SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate)
- {
- FW_CView::SetVisible(ev, visible);
-
- if (propagate)
- {
- // propagates to subviews
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- subview->SetVisible(ev, visible, TRUE);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CView::Flatten(ev, stream);
-
- stream << fExtent;
- stream << fIsContentView;
- stream << (short)fScrollingDirection;
-
- unsigned long count = CountSubViews(ev);
- short numberSubViews = (short) count;
- FW_ASSERT(count == numberSubViews);
-
- stream << numberSubViews;
- if (numberSubViews > 0)
- {
- FW_CViewIterator ite(this);
- for (FW_CView* view=ite.First(); ite.IsNotComplete(); view=ite.Next())
- FW_WRITE_DYNAMIC_OBJECT(stream, view, FW_CView);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CView::InitializeFromStream(ev, stream);
-
- FW_CPoint extent;
- FW_Boolean isContentView;
- short scrollDir;
-
- // [LSD] fExtent is set directly instead of calling SetExtent. Subviews are not yet
- // created at this point, and their layout inside this superview is defined in resources
- // anyway. (Adjustement to the frame extent is done later in CreateSubViewsFromStream)
- stream >> fExtent;
- stream >> isContentView;
- stream >> scrollDir;
-
- fScrollingDirection = FW_EScrollingDirection(scrollDir);
-
- // Declare the content view to the frame and update its extent and scrollbars
- if (isContentView)
- MakeContentView(ev);
-
- // Load the subviews
- PrivReadSubviewsFromStream(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivReadSubviewsFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivReadSubviewsFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_UNUSED(ev);
- short numberSubViews;
- stream >> numberSubViews;
- for (short i=0; i<numberSubViews; i++)
- {
- FW_CView* view;
- FW_READ_DYNAMIC_OBJECT(stream, &view, FW_CView);
- FW_ASSERT(view != NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivInvalidateCachedTransforms
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivInvalidateCachedTransforms(Environment* ev)
- {
- FW_CView::PrivInvalidateCachedTransforms(ev);
-
- if (fViewContentToFrameTransform)
- {
- fViewContentToFrameTransform->Release(ev);
- fViewContentToFrameTransform = NULL;
- }
-
- // ----- Go further down -----
- FW_CViewIterator iter(this);
- for (FW_CView* subview = iter.First(); iter.IsNotComplete(); subview = iter.Next())
- subview->PrivInvalidateCachedTransforms(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivInvalidateViewIternalTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivInvalidateViewIternalTransform(Environment* ev)
- {
- if (IsScrolling(ev))
- {
- // ----- Invalidate my internal transform -------
- if (fInternalTransform)
- {
- fInternalTransform->Release(ev);
- fInternalTransform = NULL;
- }
-
- // ----- Invalidate my viewContent to frame transform (which uses fInternalTransform) -------
- if (fViewContentToFrameTransform)
- {
- fViewContentToFrameTransform->Release(ev);
- fViewContentToFrameTransform = NULL;
- }
-
- // ----- Invalidate all subviews cached transforms -------
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- subview->PrivInvalidateCachedTransforms(ev);
- }
- else
- {
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- subview->PrivInvalidateViewIternalTransform(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivAcquireViewInternalTransform
- //----------------------------------------------------------------------------------------
-
- ODTransform* FW_CSuperView::PrivAcquireViewInternalTransform(Environment* ev) const
- {
- FW_CSuperView* self = (FW_CSuperView*)this;
- if (fInternalTransform == NULL)
- {
- if (IsScrolling(ev))
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_CPoint contentViewOffset = frame->PrivGetContentViewOffset(ev);
-
- self->fInternalTransform = FW_CopyAndRelease(ev, frame->AcquireInternalTransform(ev));
- self->fInternalTransform->MoveBy(ev, (ODPoint*)&(-contentViewOffset));
-
- FW_CPoint frameInternalTransformOffset, frameInternalTransformScale;
- self->fInternalTransform->GetPreScaleOffset(ev, (ODPoint*)&frameInternalTransformOffset);
- self->fInternalTransform->GetScale(ev, (ODPoint*)&frameInternalTransformScale);
- if (!IsScrollingInX(ev))
- {
- frameInternalTransformOffset.x = FW_kFixed0;
- frameInternalTransformScale.x = FW_kFixedPos1;
- }
- if (!IsScrollingInY(ev))
- {
- frameInternalTransformOffset.y = FW_kFixed0;
- frameInternalTransformScale.y = FW_kFixedPos1;
- }
- self->fInternalTransform->SetOffset(ev, (ODPoint*)&frameInternalTransformOffset);
- self->fInternalTransform->ScaleBy(ev, (ODPoint*)&frameInternalTransformScale);
- }
- else
- {
- self->fInternalTransform = ::FW_NewODTransform(ev);
- }
- }
-
- fInternalTransform->Acquire(ev);
- return fInternalTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSuperView::PrivAcquireContentScrollShape
- //----------------------------------------------------------------------------------------
-
- void FW_CSuperView::PrivAcquireContentScrollShape(Environment* ev,
- FW_Boolean horizontalScroll,
- FW_Boolean verticalScroll,
- ODShape* scrollShape) const
- {
- // Note: If I am scrolling it means that no other subviews can scroll. This is 'limitation'
- // of ODF because there is only one Internal transform in the ODFrame
- if (IsScrolling(ev))
- {
- if (!IsContentView(ev) && IsVisible(ev)) // ContentView already in scrollShape. See FW_CScroller::AcquireContentScrollShape
- {
- if ((verticalScroll && IsScrollingInY(ev)) || (horizontalScroll && IsScrollingInX(ev)))
- {
- FW_CAcquiredODShape aqScrollShape = ::FW_NewODShape(ev, FW_CRect(FW_kZeroPoint, GetSize(ev)));
- ViewToFrame(ev, aqScrollShape);
-
- scrollShape->Union(ev, aqScrollShape);
- }
- }
- }
- else
- {
- // ----- Look further -----
- FW_CViewIterator ite(this);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- subview->PrivAcquireContentScrollShape(ev, horizontalScroll, verticalScroll, scrollShape);
- }
- }
- }
-
-